package com.itheima.singleton.demo8;

import java.io.Serializable;

/**
 * @author zzw
 * @date 2025/8/13
 * @description 懒汉式-静态内部类
 */
public class Singleton implements Serializable {

    // 私有构造方法
    private Singleton() {}

    // 静态内部类, 该类在Singleton类被装载时并不会被装载
    private static class SingletonHolder {
        private static final Singleton INSTANCE = new Singleton();
    }

    // 获取单例对象
    public static Singleton getInstance() {
        return SingletonHolder.INSTANCE;
    }
}
